//url参数函数
function GetRequest() {
  var url = location.search; //获取url中"?"符后的字串
  var theRequest = new Object();
  if (url.indexOf("?") != -1) {
    var str = url.substr(1);
    strs = str.split("&");
    for (var i = 0; i < strs.length; i++) {
      theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
    }
  }
  return theRequest;
}

// 跳转到app
function jumpApp(url) {
  var u = navigator.userAgent;

  if (u.indexOf('Android') > -1 || u.indexOf('Adr') > -1) {//安卓环境
    //跳转到app
    window.location.href = url;
    // 1.5秒后跳转到下载页
    window.setTimeout(function () {
      window.location.href =
        "download";
    }, 1500)

  } else if (!!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) {//ios环境
    //跳转到app
    window.location.href = url;
    // 1.5秒后跳转到下载页
    window.setTimeout(function () {
      window.location.href =
        "download";
    }, 1500)

  }
}

//转换00:00格式
function formatDuring(mss) {
  var minutes = parseInt((mss % (1000 * 60 * 60)) / (1000 * 60));
  var seconds = parseInt((mss % (1000 * 60)) / 1000);
  if (minutes < 10) {
    minutes = "0" + minutes;
  }
  if (seconds < 10) {
    seconds = "0" + seconds;
  }

  return minutes + ":" + seconds;
}

// //设置自定义过期时间cookie
function setCookie(name, value, time) {
  var msec = getMsec(time); //获取毫秒
  var exp = new Date();
  exp.setTime(exp.getTime() + msec * 1);
  document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}

//将字符串时间转换为毫秒,1秒=1000毫秒
function getMsec(str) {
  var timeNum = str.substring(0, str.length - 1) * 1; //时间数量
  var timeStr = str.substring(str.length - 1, str.length); //时间单位前缀，如h表示小时

  if (timeStr == "s") //20s表示20秒
  {
    return timeNum * 1000;
  }
  else if (timeStr == "h") //12h表示12小时
  {
    return timeNum * 60 * 60 * 1000;
  }
  else if (timeStr == "d") {
    return timeNum * 24 * 60 * 60 * 1000; //30d表示30天
  }
}

//读取cookie
function getCookie(name) {
  var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"); //正则匹配
  if (arr = document.cookie.match(reg)) {
    return unescape(arr[2]);
  }
  else {
    return null;
  }
}

//删除cookie
function delCookie(name) {
  var exp = new Date();
  exp.setTime(exp.getTime() - 1);
  var cval = getCookie(name);
  if (cval != null) {
    document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
  }
}